home *** CD-ROM | disk | FTP | other *** search
- ! testINCR.bat Batch file to test the command INCR
- @echo off
- !
- ! In these comments, the espression "contains an integer" when referring to a variable value
- ! or a command argument actually means "is a string entirely consisting of the ASCII characters
- ! '0' to '9' and possibly preceded by a leading sign".
- !
- ! The format of INCR is: INCR [sign]var [BY what]
- !
- ! When <sign> is omitted, it is assumed to be '+'.
- ! When <BY what> is omitted, <what> is set to be an integer of value "1".
- !
- ! The following possibilities need to be tested:
- !
- ! Both <var> and <what> contain an integer (eg. "+42" and "-18" respectively)
- ! 1 <var> is set to %var% + what (eg. "24")
- !
- ! <var> contains a non-integer (eg. "MacDOS is OK")
- ! <what> contains a positive integer (eg. "1")
- ! <sign> is a '+'
- ! 2 <what> spaces are appended to <var> (eg. "MacDOS is OK ").
- ! <sign> is a '-'
- ! 3 <what> spaces are prepended to <var> (eg. " MacDOS is OK").
- ! <what> contains a negative integer (eg. "-3")
- ! <sign> is a '+'
- ! 4 <what> characters are removed from the end of <var> (eg. "MacDOS is").
- ! <sign> is a '-'
- ! 5 <what> characters are removed from the beginning of <var> (eg. "DOS is OK").
- ! <what> contains a non-integer (eg. "?!?")
- ! <sign> is a '+'
- ! 6 <what> is appended to <var> (eg. "MacDOS is OK?!?").
- ! <sign> is a '-'
- ! 7 <what> is prepended to <var> (eg. "?!?MacDOS is OK").
- !
- ! Note: a basic test was done before executing this batch file.
- !
- ! Copyright © 1993 by Rainbow Hill Pty Ltd. All rights reserved.
- !
-
- set test =1
-
- !--------------------------------------here the tests begin-----------------------------------------
- :LBL_1
- ! +numeric default
- set var =+5
- set cntl =6
- set remark =incr "%var%"
- incr var
- goto REPORT_LBL
-
- :LBL_2
- ! numeric default
- set var =0
- set cntl =1
- set remark =incr "%var%"
- incr var
- goto REPORT_LBL
-
- :LBL_3
- ! -numeric default
- set var =-4
- set cntl =-3
- set remark =incr "%var%"
- incr var
- goto REPORT_LBL
-
- :LBL_4
- ! sign -numeric default
- set var =-1
- set cntl =0
- set remark =incr -"%var%"
- incr -var
- goto REPORT_LBL
-
- :LBL_5
- ! +numeric +numeric
- set var =33
- set what =11
- set cntl =44
- goto STD_TEST_LBL
-
- :LBL_6
- ! +numeric -numeric
- set var =11
- set what =-33
- set cntl =-22
- goto STD_TEST_LBL
-
- :LBL_7
- ! +numeric alpha
- set var =1234567
- set what =87654321a
- set cntl =123456787654321a
- goto STD_TEST_LBL
-
- :LBL_8
- ! alpha alpha
- set var =this
- set what = is right
- set cntl =this is right
- goto STD_TEST_LBL
-
- :LBL_9
- ! sign alpha alpha
- set var = front
- set what =back to
- set cntl =back to front
- set remark =incr -"%var%" by "%what%"
- incr -var by %what%
- goto REPORT_LBL
-
- :LBL_10
- ! alpha +numeric
- set var =three spaces:
- set what =3
- set cntl =three spaces:
- goto STD_TEST_LBL
-
- :LBL_11
- ! alpha -numeric
- set var =clean !vsd67504fv0-v
- set what =-13
- set cntl =clean !
- goto STD_TEST_LBL
-
- :LBL_12
- ! alpha -numeric
- set var =nothing left
- set what =-12
- ! When 'var' is set to nothing, it is removed from the variable list. When we try to
- ! check it later on, it is not replaced because it does not exist. <cntl> is set to
- ! "%VAR%" so that the check succeeds, confirming that 'var' was removed.
- set cntl =%%VAR%%
- goto STD_TEST_LBL
-
- :LBL_13
- ! alpha -numeric
- set var =less than nothing left !
- set what =-100000
- set cntl =%%VAR%%
- goto STD_TEST_LBL
-
- :LBL_14
- ! alpha +numeric
- set var =maximum length line (currently 127 characters)
- set what =+100000
- set remark =incr "%var%" by "%what%"
- incr var by %what%
- ! we have to cut some of the spaces before making the comparison, because the command line
- ! itself cannot be longer than 127 and the 'IF' would not be executable. Let's chop 126
- ! characters, so that we are just left with a single 'm'.
- incr var by -126
- set cntl =m
- goto REPORT_LBL
-
- :LBL_15
- ! sign alpha +numeric
- set var =: three spaces
- set what =3
- set cntl = : three spaces
- set remark =incr -"%var%" by "%what%"
- incr -var by %what%
- goto REPORT_LBL
-
- :LBL_16
- ! sign alpha -numeric
- set var =vsd67504fv0-vclean !
- set what =-13
- set cntl =clean !
- set remark =incr -"%var%" by "%what%"
- incr -var by %what%
- goto REPORT_LBL
-
- :LBL_17
- ! sign alpha -numeric
- set var =nothing left
- set what =-12
- ! When 'var' is set to nothing, it is removed from the variable list. When we try to
- ! check it later on, it is not replaced because it does not exist. <cntl> is set to
- ! "%VAR%" so that the check succeeds, confirming that 'var' was removed.
- set cntl =%%VAR%%
- set remark =incr -"%var%" by "%what%"
- incr -var by %what%
- goto REPORT_LBL
-
- :LBL_18
- ! sign alpha -numeric
- set var =less than nothing left !
- set what =-100000
- set cntl =%%VAR%%
- set remark =incr -"%var%" by "%what%"
- incr -var by %what%
- goto REPORT_LBL
-
- :LBL_19
- ! sign alpha +numeric
- set var =maximum length line (currently 127 characters)
- set what =+100000
- set remark =incr -"%var%" by "%what%"
- incr -var by %what%
- ! we have to cut some of the spaces before making the comparison, because the command line
- ! itself cannot be longer than 127 and the 'IF' would not be executable. Let's chop 126
- ! characters from the beginning, so that we are just left with a single ')'.
- incr -var by -126
- set cntl =)
- goto REPORT_LBL
-
- !--------------------------------------standard test-----------------------------------------------
- :STD_TEST_LBL
- set remark =incr "%var%" by "%what%"
- incr var by %what%
- ! then it falls through to the report...
-
- !-----------------------------routine to report the result of a test--------------------------------
- :REPORT_LBL
- if %var%==%cntl% goto SUCCESS_LBL
- echo Test %test% (%remark% = "%var%") failed: the result should have been "%cntl%"
- goto CONTINUE_LBL
- :SUCCESS_LBL
- echo off
- echo Test %test% (%remark% = "%var%") successful
- :CONTINUE_LBL
- incr test
- goto LBL_%test%
- ! when the last test is done, it will just fall through...
-
- !---------------------------------- That's it folks ! ----------------------------------------------
- set remark=
- set var=
- set what=
- set cntl=
- set test=